package com.taxiApp.server.impl;

import com.taxiApp.mapper.UserMapper;
import com.taxiApp.domain.User;
import com.taxiApp.server.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class UserServerImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    public User getUser(User user) {
        return userMapper.getUser(user);
    }

    public void saveUser(User user) {
        userMapper.saveUser(user);

    }

    public List<User> getAllDriver() {
        User user = new User();
        user.setUserType(2); //1表示司机
        List<User> users = userMapper.getUsers(user);

        if (users != null) {
            return users;
        } else
            return Collections.emptyList();

    }

    public List<User> getAllPassenger() {
        User user = new User();
        user.setUserType(1); //1表示乘客
        List<User> users = userMapper.getUsers(user);

        if (users != null) {
            return users;
        } else
            return Collections.emptyList();
    }

    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void changePwd(User user) {
        userMapper.changePwd(user);
    }
}
